<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css" />
</head>

<body>

    <body class="pear-container">
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="fjlb-table" lay-filter="fjlb-table"></table>
            </div>
        </div>
    </body>

    <script type="text/html" id="fjlb-bar">
		    <button class="pear-btn pear-btn-sm" lay-event="jf"> 解封</button>
	</script>
    <script type="text/html" id="id">
        {{d.LAY_TABLE_INDEX+1}}
    </script>

    <script src="../../component/layui/layui.js"></script>
    <script src="../../component/pear/pear.js"></script>
    <script>
        layui.use(['table', 'form', 'jquery'], function () {
            let table = layui.table;
            let form = layui.form;
            let $ = layui.jquery;

            let MODULE_PATH = "/system/user/";

            let cols = [
                [
                    {
                        title: '序号',
                        field: 'username',
                        align: 'center',
                        width: 100,
                        templet:"#id"
                    },
                    {
                        title: '昵称',
                        field: 'nickname',
                        align: 'center'
                    },
                    {
                        title: '用户ID',
                        field: 'uid',
                        align: 'center'
                    },
                    {
                        title: '操作',
                        toolbar: '#fjlb-bar',
                        align: 'center',
                        width: 130
                    }
                ]
            ]

            table.render({
                elem: '#fjlb-table',
                url: '/api/user/ban/list',
                page: true,
                cols: cols,
                skin: 'line',
                defaultToolbar: [{
                    layEvent: 'refresh',
                    icon: 'layui-icon-refresh',
                }, 'filter', 'print', 'exports']
            });

            table.on('tool(fjlb-table)', function (obj) {
                if (obj.event === 'jf') {
                    window.jf(obj);
                } else if (obj.event === 'edit') {
                    window.edit(obj);
                }
            });

            table.on('toolbar(fjlb-table)', function (obj) {
                if (obj.event === 'add') {
                    window.add();
                } else if (obj.event === 'refresh') {
                    window.refresh();
                } 
            });

            form.on('submit(fjlb-query)', function (data) {
                table.reload('fjlb-table', {
                    where: data.field
                })
                return false;
            });

            form.on('switch(fjlb-enable)', function (obj) {
                layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
            });

            window.jf = function (obj) {
                layer.confirm('确定要解封吗？', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    layer.close(index);
                    let loading = layer.load();
                    $.ajax({
                        url: "/api/user/unban/" + obj.data.uid,
                        dataType: 'json',
                        success: function (result) {
                            layer.close(loading);
                            if (result.msg == "解封成功") {
                                layer.msg(result.msg, {
                                    icon: 1,
                                    time: 1000
                                }, function () {
                                    table.reload('fjlb-table');
                                });
                            } else {
                                layer.msg(result.msg, {
                                    icon: 2,
                                    time: 1000
                                });
                            }
                        }
                    })
                });
            }


            window.refresh = function (param) {
                table.reload('fjlb-table');
            }
        })
    </script>
</body>

</html>